#include "route.h"

void menu()
{
    printf("\n*****************************************\n");
    printf("*****   1. AddVex     2. AddArc     *****\n");
    printf("*****   3. DelVex     4. DelArc     *****\n");
    printf("*****   5. SearchVex  6. SearchArc  *****\n");
    printf("*****   7. ModifyVex  8. ModifyArc  *****\n");
    printf("*****   9. ShowVex    10.ShowArc    *****\n");
    printf("*****   11.ShowMap    12.ShowMatrix *****\n");
    printf("*****   13.ClearMap   14.SHowPath   *****\n");
    printf("*****   15.ClearArc   16.LayCircuit *****\n");
    printf("*****       17.PASSALLVexPath       *****\n");
    printf("*****       18.PASSALLVexLoop       *****\n");
    printf("*****         19.TSP_Berlin         *****\n");
    printf("*****            0.exit             *****\n");
    printf("*****************************************\n");
}

int main()
{
    int input = 0;
    // 创建地图
    Map map;

    // 初始化地图
    InitMap(filename, &map);

    do
    {
        string str;
        sleep(1);
        menu();
        printf("请选择>:");
        scanf("%d", &input);
        switch (input)
        {
        case ADDVex:
            cout << endl
                << "==============  增加地点  ===============" << endl
                << endl;
            AddVexMap(&map);
            break;
        case ADDArc:
            cout << endl
                << "==============  增加道路  ===============" << endl
                << endl;
            AddArcMap(&map);
            break;
        case DELVex:
            cout << endl
                << "==============  删除地点  ===============" << endl
                << endl;
            DelVexMap(&map);
            break;
        case DELArc:
            cout << endl
                << "==============  删除道路  ===============" << endl
                << endl;
            DelArcMap(&map);
            break;
        case SEARCHVex:
            cout << endl
                << "==============  查找地点  ===============" << endl
                << endl;
            SearchVexMap(&map);
            break;
        case SEARCHArc:
            cout << endl
                << "==============  查找道路  ===============" << endl
                << endl;
            SearchArcMap(&map);
            break;
        case MODIFYVex:
            cout << endl
                << "==============  修改地点  ===============" << endl
                << endl;
            ModifyVexMap(&map);
            break;
        case MODIFYArc:
            cout << endl
                << "==============  修改道路  ===============" << endl
                << endl;
            //ModifyArcMap(&map);
            cout << "= 道路信息由地点自动决定，无修改权限！ =" << endl;
            break;
        case SHOWVex:
            cout << endl
                << "==============  显示地点  ===============" << endl
                << endl;
            ShowVexMap(&map);
            break;
        case SHOWArc:
            cout << endl
                << "==============  显示道路  ===============" << endl
                << endl;
            ShowArcMap(&map);
            break;
        case SHOWMap:
            cout << endl
                << "==============  显示地图  ===============" << endl
                << endl;
            ShowMap(&map);
            break;
        case SHOWMatrix:
            cout << endl
                << "==============  显示矩阵  ===============" << endl
                << endl;
            ShowMatrix(&map);
            break;
        case CLEARMap:
            cout << "您确定清空地图吗?确定请输入yes,返回请输入no>: " << endl;

            cin >> str;
            if (str == "yes")
            {
                cout << endl
                    << "==========  正在格式化地图...  ===========" << endl
                    << endl;
                sleep(1);
                ClearMap(&map);
                cout << endl
                    << "==========  地图已被格式化!    ===========" << endl
                    << endl;
            }
            else if (str == "no")
            {
                break;
            }
            else
            {
                cout << "输入错误!" << endl;
                break;
            }
        case SHOWPath:
            cout << endl
                << "============  输入一个地点A  ============" << endl
                << "==  显示A到其他所有地点的最短简单路径  ==" << endl
                << "=============  [递增输出]  ==============" << endl
                << endl;
            sleep(1);
            ShowShortest_Path(&map);
            break;

        case CLEARArc:
            cout << "您确定清空道路吗?确定请输入yes,返回请输入no>: " << endl;
            cin >> str;
            if (str == "yes")
            {
                cout << endl
                    << "==========    正在清除所有道路...  ===========" << endl
                    << endl;
                sleep(1);
                ClearArc(&map);
                printf("\n@@@@@@@@@@@   清除所有道路成功!  @@@@@@@@@@@\n");
                break;
            }
            else if (str == "no")
            {
                break;
            }
            else
            {
                cout << "输入错误!" << endl;
                break;
            }
        case LAYCIRCUIT:
            cout << endl
                << "==========    正在生成电路规划...  ===========" << endl
                << "==========   [Prim generate MST]  ===========" << endl
                << endl;
            sleep(1);
            Lay_Circuit(&map);
            cout << "==========    电路铺设已显示完成!  ===========" << endl;
            break;
        case PASSALLVexPath:
            cout << endl
                << "==========    正在生成指定路线...  ===========" << endl
                << "=  [某地出发经过所有地点(可重复经过)距离最短]  =" << endl
                << endl;
            PassAllVex_Path(&map);
            cout << "==========    指定路线已生成完成!  ===========" << endl;
            break;
        case PASSALLVexLoop:
            cout << endl
                << "==========    正在生成指定路线...  ===========" << endl
                << "[某地出发经过所有地点(可重复经过)回到原点距离最短]" << endl
                << endl;
            PassAllVex_Loop(&map);
            cout << "==========    指定路线已生成完成!  ===========" << endl;
            break;
        case TSP_Berlin:
            cout << endl
                << "==========    正在生成指定路线...  ===========" << endl
                << "[某地出发经过所有地点回到原点距离最短]" << endl
                << endl;
            Tsp_Berlin();
            cout << "==========    指定路线已生成完成!  ===========" << endl;
            break;
        case EXIT:
            cout << endl
                << "==========    正在保存文件...  ===========" << endl
                << endl;
            sleep(1);
            SaveMap(filename, &map);
            printf("\n@@@@@@@@@@@   保存文件成功!  @@@@@@@@@@@\n");

            ClearMap(&map);
            printf("\n#############  退出地图    #############\n");

            break;
        default:
            printf("\n选择错误\n");
            break;
        }
    } while (input);

    return 0;
}